function [hist, bin] = histc(data, binvec)
  if find(size(data) == 1)
    hist = zeros( 1, length(binvec) );
    if nargout == 2
      bin = -1 * ones( 1, length(data) );
    end
    for i = 1:length(binvec)-1
      ind = find(data >= binvec(i) & data < binvec(i+1));
      hist(i) = length(ind);
      if nargout == 2
	bin(ind) = i;
      end
    endfor
    hist(end) = sum(data == binvec(end));
  else
    hist = zeros(length(binvec), size(data, 2));
    for i = 1:length(binvec)-1
      hist(i,:) = sum(data(:,1:end) >= binvec(i) & data(:,1:end) < binvec(i+1));
    endfor
    hist(end,:) = sum(data(:,1:end) == binvec(end));
  endif
endfunction
